﻿using System;

namespace IupNET
{
    public class PaintArea:Control
    {
       
        

        public PaintArea()
            : base(Iupc.Canvas(null))
        {
           
        }

        internal PaintArea(IntPtr obj)
            : base(obj)
        {
            //we use this constructor to inherit (to GL canvas)
        }

        public bool BackingStore
        {
            get
            {
                return GetAttribute("BACKINGSTORE") == "YES";
            }
            set
            {
                SetAttribute("BACKINGSTORE", value ? "YES" : "NO");
            }
        }

        public bool Border
        {
            get
            {
                return GetAttribute("BORDER") == "YES";
            }
            set
            {
                SetAttribute("BORDER", value ? "YES" : "NO");
            }
        }

        public bool CanFocus
        {
            get
            {
                return GetAttribute("CANFOCUS") == "YES";
            }
            set
            {
                SetAttribute("CANFOCUS", value ? "YES" : "NO");
            }
        }

        public string ClipRect
        {   //TODO: use rectangle instead of string
            get
            {
                return GetAttribute("CLIPRECT");
            }
            set
            {
                SetAttribute("CLIPRECT", value);
            }
        }

        public Cursor Cursor
        {
            get
            {
                return Convert.StringToCursor(GetAttribute("CURSOR"));
            }
            set
            {
                SetAttribute("CURSOR",Convert.CursorToString(value));
            }
        }

        /// <summary>
        /// [Windows and GTK Only] (non inheritable): Enable or disable the drag-drop of files. 
        /// Default: false, but if DropFilesCB is defined when the element is mapped then it will 
        /// be automatically enabled.
        /// </summary>
        public bool DragDrop
        {
            get
            {
                return GetAttribute("DRAGDROP") == "YES";
            }
            set
            {
                SetAttribute("DRAGDROP", value ? "YES" : "NO");
            }
        }

        public Size2i DrawSize
        {
            get
            {
                return Convert.StringToSize(GetAttribute("DRAWSIZE"));
            }
            set
            {
                SetAttribute("DRAWSIZE", Convert.SizeToString(value));
            }
        }

        public IntPtr HDCWMPaint
        {
            get
            {
                return Iupc.GetAttributePtr(cobject, "HDC_WMPAINT");
            }
        }

        public IntPtr HWND
        {
            get
            {
                return Iupc.GetAttributePtr(cobject, "HWND");
            }
        }

        public Scrollbar Scrollbar
        {
            get
            {
                return Convert.StringToScrollbar(GetAttribute("SCROLLBAR"));
            }
            set
            {
                SetAttribute("SCROLLBAR", Convert.ScrollbarToString(value));
            }
        }

        public double DX
        {
            get
            {
                return (double)Iupc.GetFloat(cobject, "DX");
            }
            set
            {
                SetAttribute("DX",Convert.RealToString(value));
            }
        }

        public double DY
        {
            get
            {
                return (double)Iupc.GetFloat(cobject, "Y");
            }
            set
            {
                SetAttribute("DY", Convert.RealToString(value));
            }
        }

        public double PosX
        {
            get
            {
                return (double)Iupc.GetFloat(cobject, "POSX");
            }
            set
            {
                SetAttribute("POSX", Convert.RealToString(value));
            }
        }

        public double PosY
        {
            get
            {
                return (double)Iupc.GetFloat(cobject, "POSY");
            }
            set
            {
                SetAttribute("POSY", Convert.RealToString(value));
            }
        }

        public double XMin
        {
            get
            {
                return (double)Iupc.GetFloat(cobject, "XMIN");
            }
            set
            {
                SetAttribute("XMIN", Convert.RealToString(value));
            }
        }

        public double XMax
        {
            get
            {
                return (double)Iupc.GetFloat(cobject, "XMAX");
            }
            set
            {
                SetAttribute("XMAX", Convert.RealToString(value));
            }
        }

        public double YMin
        {
            get
            {
                return (double)Iupc.GetFloat(cobject, "YMIN");
            }
            set
            {
                SetAttribute("YMIN", Convert.RealToString(value));
            }
        }

        public double YMax
        {
            get
            {
                return (double)Iupc.GetFloat(cobject, "YMAX");
            }
            set
            {
                SetAttribute("YMAX", Convert.RealToString(value));
            }
        }

        public double LineX
        {
            get
            {
                return (double)Iupc.GetFloat(cobject, "LINEX");
            }
            set
            {
                SetAttribute("LINEX", Convert.RealToString(value));
            }
        }

        public double LineY
        {
            get
            {
                return (double)Iupc.GetFloat(cobject, "LINEY");
            }
            set
            {
                SetAttribute("LINEY", Convert.RealToString(value));
            }
        }

        public bool XAutoHide
        {
            get
            {
                return GetAttribute("XAUTOHIDE") == "YES";
            }
            set
            {
                SetAttribute("XAUTOHIDE", value ? "YES" : "NO");
            }
        }

        public bool YAutoHide
        {
            get
            {
                return GetAttribute("YAUTOHIDE") == "YES";
            }
            set
            {
                SetAttribute("YAUTOHIDE", value ? "YES" : "NO");
            }
        }

        public IntPtr XDisplay
        {
            get
            {
                return Iupc.GetAttributePtr(cobject, "XDISPLAY");
            }
        }

        public IntPtr XWindow
        {
            get
            {
                return Iupc.GetAttributePtr(cobject, "XWINDOW");
            }
        }

        public EventCallback Action
        {
            get
            {
                return CBHandler.Fetch("ACTION_CANVAS");
            }
            set
            {
                CBHandler.Set("ACTION_CANVAS", value);
            }
        }

        public EventCallback ButtonCB
        {
            get
            {
                return CBHandler.Fetch("BUTTON_CB");
            }
            set
            {
                CBHandler.Set("BUTTON_CB", value);
            }
        }

        public EventCallback DropFilesCB
        {
            get
            {
                return CBHandler.Fetch("DROPFILES_CB");
            }
            set
            {
                CBHandler.Set("DROPFILES_CB", value);
            }
        }

        public EventCallback FocusCB
        {
            get
            {
                return CBHandler.Fetch("FOCUS_CB");
            }
            set
            {
                CBHandler.Set("FOCUS_CB", value);
            }
        }


        public EventCallback MotionCB
        {
            get
            {
                return CBHandler.Fetch("MOTION_CB");
            }
            set
            {
                CBHandler.Set("MOTION_CB", value);
            }
        }

        public EventCallback KeyPressCB
        {
            get
            {
                return CBHandler.Fetch("KEYPRESS_CB");
            }
            set
            {
                CBHandler.Set("KEYPRESS_CB", value);
            }
        }

        public EventCallback ResizeCB
        {
            get
            {
                return CBHandler.Fetch("RESIZE_CB");
            }
            set
            {
                CBHandler.Set("RESIZE_CB", value);
            }
        }

        public EventCallback ScrollCB
        {
            get
            {
                return CBHandler.Fetch("SCROLL_CB");
            }
            set
            {
                CBHandler.Set("SCROLL_CB", value);
            }
        }

        public EventCallback WheelCB
        {
            get
            {
                return CBHandler.Fetch("WHEEL_CB");
            }
            set
            {
                CBHandler.Set("WHEEL_CB",value);
            }
        }

        public Canvas CreateCanvas()
        {
            return new Canvas(this);
        }
    }
}
